package com.itcast.impl;

import com.itcast.bean.BaseRespBean;
import com.itcast.bean.Location.reqUserLocation.request.LocationRequestBean;
import com.itcast.bean.Location.reqUserLocation.response.LocationResponseBean;
import com.itcast.bean.Location.requestNearbyLocation.request.RequestNearbyLocationBean;
import com.itcast.bean.Location.requestNearbyLocation.response.ResponseNearbyLocationBean;
import com.itcast.bean.Position;
import com.itcast.bean.account.response.AccountResponseBean;
import com.itcast.dao.LocationDao;
import com.itcast.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("locationService")
@Transactional(rollbackFor = Exception.class)
public class LocationServiceImpl implements LocationService {

    @Autowired
    LocationDao locationDao;

    @Override
    public BaseRespBean requestUserLocation(LocationRequestBean locationRequestBean) {

        LocationResponseBean accountResponseBean =new LocationResponseBean();
        Position position=new Position();
        position.setX(116.394855f);
        position.setY(39.912046f);
        accountResponseBean.setPosition(position);
        accountResponseBean.setOpenId(locationRequestBean.openId);
        accountResponseBean.setRespMsg("查询成功");
        return accountResponseBean;
    }

    @Override
    public BaseRespBean requestNearbyLocation(RequestNearbyLocationBean requestNearbyLocationBean) {

        List<Position> positions=locationDao.findAll();

        ResponseNearbyLocationBean responseNearbyLocationBean=new ResponseNearbyLocationBean();
        positions=locationDao.search(requestNearbyLocationBean);
        responseNearbyLocationBean.setPositions(positions);
        responseNearbyLocationBean.setRespMsg("查询成功");
        return responseNearbyLocationBean;
    }

}